<template>
  <div class="inputbox">
    <div>
      <input type="text" placeholder="用户名" v-model="user_name">
    </div>
    <div>
      <input type="text" placeholder="密码" v-model="user_password">
    </div>
    <div>
      <input type="text" placeholder="确认密码" v-model="user_passwordA">
    </div>
    <div class="btn-login" @click="toRegister">注册</div> 
  </div>
</template>

<script>
import axios from "axios";
export default {
  name: "RegisterInput",
  data() {
    return {
      user_name:"",
      user_password:"",
      user_passwordA:""

    };
  },
  methods: {
    toRegister() {
      if(this.user_name == ""){
        alert("用户名不能为空")
      }else if(this.user_password == ""){
        alert("密码不能为空")
      }else if(this.user_passwordA == ""){
        alert("请确认密码")
      }else if(this.user_password == this.user_passwordA){
        axios.get("/api/register.json?user_name="+this.user_name+"&user_password="+this.user_password)
        .then(this.toRegisterSucc);
      }
      
    },
    toRegisterSucc(res){
      if(res.status == 200 && res.data){
        alert(res.data.result)
        this.$router.push('my')
      }
    }
  }
};
</script>
<style lang="scss" scoped>
@import "~styles/varibles.styl";

.inputbox {
  position: relative;
  top: 1rem;
  left: 0;
  right: 0;
  margin: 0 auto;
  width: 90vw;
  height: 40vh;
  // background: $bgColor;
  overflow: hidden;
  font-size: 0.32rem;
  display: flex;
  -webkit-justify-content: space-around;
  justify-content: space-around;
  flex-direction:column ;
  input{
    width: 80vw;
    height: 0.8rem;
    border-radius: 0.5rem;
    padding: 0.1rem 5vw;
    box-shadow: 0.01rem 0.01rem 0.1rem $bgColor;
  }
  .btn-login{
    position: relative;
    right: 0;
    left: 0;
    width: 2rem;
    height: 1rem;
    text-align: center;
    line-height: 1rem;
    box-shadow: 0.01rem 0.01rem 0.1rem $bgColor;
    border-radius: 0.5rem;
    margin: 0 auto;
    &:active{
      box-shadow: 0.01rem 0.01rem 0.1rem green inset;
    }
  }
  
}
</style>
